﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using IronOne.SalesOne.BusinessObjects;
using System.Data.SqlClient;
using System.IO;


namespace IronOne.SalesOne.DataObjects
{
    class Mapper
    {

        #region Policy
        internal static Policy ToPolicyObject(PolicyEntity p)
        {

            return new Policy
            {
                
                ContractId = p.ContractId,
                CustomerId = p.CustomerID,
                PlanCode = p.PlanCode.ToString(),
                PolicyState = p.PolicyStatusEntity == null ? string.Empty : p.PolicyStatusEntity.Description == null ? string.Empty : p.PolicyStatusEntity.Description,
                SumAssured = p.SumAssured,
                Suspence = p.Suspence == null ? 0 : (float)p.Suspence,
                Term = p.Term == null ? 0 : (int)p.Term,
                Premium = p.Premium == null ? 0 : (decimal)p.Premium,
                PlicyActiveStatus = p.PolicyActiveStatus,
                SOCode = p.SOCode,
                DueDate = p.DueDate == null ? string.Empty : p.DueDate.ToShortDateString(),                
                RiskDate = p.RiskDate == null ? string.Empty : p.RiskDate.Value.ToShortDateString(),
                PayMode = p.PaymentModeEntity == null ? string.Empty : p.PaymentModeEntity.Description == null ? string.Empty : p.PaymentModeEntity.Description,
                LastUpdatedDate = p.LastUpdated == null ? string.Empty : p.LastUpdated.Value.ToShortDateString(),
                CollectionDue = p.CollectionDue == null ? 0 : (float)p.CollectionDue,
                AckStatus = p.AckStatus,
                PolicyType = p.PolicyTypeEntity == null ? string.Empty : p.PolicyTypeEntity.Description == null ? string.Empty : p.PolicyTypeEntity.Description
                



            };

            //p.LastUpdatedDate.Value.ToShortDateString(),
            //(Convert.ToDateTime(p.LastUpdatedDate).ToShortDateString()),
        }

        internal static PolicyEntity ToPolicyEntity(Policy policy)
        {
            return new PolicyEntity
            {
                ContractId = policy.ContractId,
                CustomerID = policy.CustomerId,
                DueDate = Convert.ToDateTime(policy.DueDate),
                Premium = (decimal)policy.Premium,
                PayMode = int.Parse(policy.PayMode),
                PolicyState = int.Parse(policy.PolicyState),
                Suspence = policy.Suspence,
                PlanCode = policy.PlanCode,                
                SumAssured = policy.SumAssured,               
                Term = (int)policy.Term,                
                PolicyActiveStatus = policy.PlicyActiveStatus,
                SOCode = policy.SOCode,                
                RiskDate = Convert.ToDateTime(policy.RiskDate),                
                LastUpdated = Convert.ToDateTime(policy.LastUpdatedDate),
                CollectionDue = policy.CollectionDue,
                AckStatus = policy.AckStatus,
                PolicyType = int.Parse(policy.PolicyType)



            };
        }

        #endregion


        #region PendingProposal
        internal static PendingProposal ToPendingProposalObject(PendingProposalEntity p)
        {

            return new PendingProposal
            {

                ContractId = p.ContractId,
                ProposalDate = p.ProposalDate == null ? string.Empty : p.ProposalDate.Value.ToShortDateString(),
                PendingRequirement = p.PendingRequirementEntity == null ? string.Empty : p.PendingRequirementEntity.Description == null ? string.Empty : p.PendingRequirementEntity.Description,                
                Comments = p.Comments,
                LifeNo = p.LifeNo,
                LifeName = p.LifeName,
                Status = p.Status,
                SOCode = p.SOCode,
                LastUpdated = p.LastUpdated == null ? string.Empty : p.LastUpdated.Value.ToShortDateString(),
                



            };

            //p.LastUpdatedDate.Value.ToShortDateString(),
            //(Convert.ToDateTime(p.LastUpdatedDate).ToShortDateString()),
        }

        internal static PendingProposalEntity ToPendingProposalEntity(PendingProposal p)
        {
            return new PendingProposalEntity
            {
                ContractId = p.ContractId,

                ProposalDate = Convert.ToDateTime(p.ProposalDate),
                PendingRequirement = int.Parse(p.PendingRequirement),
                Comments = p.Comments,
                LifeNo = p.LifeNo,
                LifeName = p.LifeName,
                Status = p.Status,
                SOCode = p.SOCode,
                LastUpdated = Convert.ToDateTime(p.LastUpdated)


            };
        }

        #endregion


        #region Claim
        internal static Claim ToClaimObject(ClaimEntity c)
        {

            return new Claim
            {

                ClaimNo = c.ClaimNo,
                AssignDate = c.AssignDate == null ? string.Empty : c.AssignDate.Value.ToShortDateString(),
                ClaimStatus = c.ClaimStatus,
                ContractNo = c.ContractNo,
                LastUpdated = c.LastUpdated == null ? string.Empty : c.LastUpdated.Value.ToShortDateString(),
                PendingReason = c.PendingReason,
                Remarks = c.Remarks,
                ReplyDate = c.ReplyDate == null ? string.Empty : c.ReplyDate.Value.ToShortDateString(),
                CustomerId = c.CustomerId,
                SOCode = c.SOCode





            };
        }

        internal static ClaimEntity ToComplaintEntity(Claim c)
        {
            return new ClaimEntity
            {
                ClaimNo = c.ClaimNo,
                AssignDate = Convert.ToDateTime(c.AssignDate),
                ClaimStatus = c.ClaimStatus,
                ContractNo = c.ContractNo,
                LastUpdated = Convert.ToDateTime(c.LastUpdated),
                PendingReason = c.PendingReason,
                Remarks = c.Remarks,
                ReplyDate = Convert.ToDateTime(c.ReplyDate),
                CustomerId = c.CustomerId,
                SOCode = c.SOCode,





            };
        }

        #endregion


        #region Complaint

        internal static Complaint ToComplaintObject(ComplaintEntity c)
        {

            return new Complaint
            {

                ComplaintId = c.ComplaintId,
                AssignDate = c.AssignedDate == null ? string.Empty : c.AssignedDate.Value.ToShortDateString(),
                ComplaintStatus = c.ComplaintStatus == null ? 0 : c.ComplaintStatus,
                ContractNo = c.ContractNo,
                LastUpdated = c.LastUpdated == null ? string.Empty : c.LastUpdated.Value.ToShortDateString(),
                ActionRequired = c.ActionRequired,
                Remarks = c.Remarks,
                ReplyDate = c.ReplyDate == null ? string.Empty : c.ReplyDate.Value.ToShortDateString(),
                CustomerId = c.CustomerId,
                SOCode = c.SOCode,
                ComplaintSubType = c.ComplaintSubType == null ? 0 : c.ComplaintSubType,
                ComplaintType = c.ComplaintType == null ? 0 : c.ComplaintType,
                InformMethod = c.InformMethod

            };
        }


        internal static ComplaintEntity ToComplaintEntity(Complaint c)
        {
            return new ComplaintEntity
            {
                ComplaintId = c.ComplaintId,
                //AssignedDate = Convert.ToDateTime(c.AssignDate),
                ComplaintStatus = c.ComplaintStatus,
                //ContractNo = c.ContractNo,
                LastUpdated = Convert.ToDateTime(c.LastUpdated),
                //ActionRequired = c.ActionRequired,
                Remarks = c.Remarks,
                //ReplyDate = Convert.ToDateTime(c.ReplyDate),
                CustomerId = c.CustomerId,
                //SOCode = c.SOCode,
                //ComplaintSubType = c.ComplaintSubType,
                //ComplaintType = c.ComplaintType,
                //InformMethod = c.InformMethod






            };
        }



        #endregion

        #region Group
        internal static SalesOneGroup ToGroupObject(GroupEntity g)
        {

            return new SalesOneGroup
            {
                GroupId = g.GroupId,
                Code = g.GroupCode,
                Name = g.GroupName,
                EffectFrom = g.EffectiveFrom == null ? string.Empty : g.EffectiveFrom.ToShortDateString(),
                EffectTo = g.EffectiveTo == null ? string.Empty : g.EffectiveTo.ToShortDateString(),
                LastUpdated = g.LastUpdated == null ? string.Empty : g.LastUpdated.Value.ToShortDateString(),
                


            };
        }

        internal static GroupEntity ToGroupEntity(SalesOneGroup group)
        {
            return new GroupEntity
            {
                GroupId = group.GroupId,
                GroupCode = group.Code,
                GroupName = group.Name,
                EffectiveFrom = Convert.ToDateTime(group.EffectFrom),
                EffectiveTo = Convert.ToDateTime(group.EffectTo),
                LastUpdated = Convert.ToDateTime(group.LastUpdated)
            };
        }

        #endregion


        #region Branch
        internal static Branch ToBranchObject(BranchEntity b)
        {

            return new Branch
            {
                BranchId = b.BranchId,
                GroupId = b.GroupId,
                BranchCode = b.BranchCode,
                BranchName = b.BranchName,
                Address1 = b.Address1,
                Address2 = b.Address2,
                City = b.City,
                //Country = b.Country,
                //Country =b.Country== null ? String.Empty : 
                Country = b.Country == null ? String.Empty : b.CountryEntity.Description,
                // Country = cs.Country == null ? String.Empty : cs.CountryEntity.Description,
                PostalCode = b.PostalCode,
                ContactNo = b.ContactNo,
                EffectiveFrom = b.EffectiveFrom.ToShortDateString(),
                EffectiveTo = b.EffectiveTo.ToShortDateString(),


            };
        }

        internal static BranchEntity ToBranchEntity(Branch branch)
        {
            return new BranchEntity
            {
                BranchId = (short)branch.BranchId,
                GroupId = branch.GroupId,
                BranchCode = branch.BranchCode,
                BranchName = branch.BranchName,
                Address1 = branch.Address1,
                Address2 = branch.Address2,
                City = branch.City,
                Country = Convert.ToInt32(branch.Country),
                //Country = branch.Country,
                //Country = Convert.ToInt32(branch.Country),
                PostalCode = branch.PostalCode,
                ContactNo = branch.ContactNo,
                EffectiveFrom = Convert.ToDateTime(branch.EffectiveFrom),
                EffectiveTo = Convert.ToDateTime(branch.EffectiveTo),


            };
        }

        #endregion


        #region UserType
        internal static UserType ToUserTypeObject(UserTypeEntity ut)
        {

            return new UserType
            {
                UserTypeId = ut.UserTypeId,
                UserTypeName = ut.UserTypeName,
                LoweredUserTypeName = ut.LoweredUserTypeName,
                Description = ut.Description,

            };
        }

        internal static UserTypeEntity ToUserTypeEntity(UserType utype)
        {
            return new UserTypeEntity
            {
                UserTypeId = (Int16)utype.UserTypeId,
                UserTypeName = utype.UserTypeName,
                LoweredUserTypeName = utype.LoweredUserTypeName,
                Description = utype.Description,
            };
        }

        #endregion



        #region Expenses
        internal static Expense ToExpenseObject(ExpenseEntity e)
        {

            return new Expense
            {
                CustomerId = e.CustomerID,
                ExpenseId = e.ExpenseID,
                ExpenseName = e.ExpenseName,
                ExpenseValue = (float)e.ExpenseValue,
                Food = (float)e.Food,
                HouseExp = (float)e.HouseExp,
                Transport = (float)e.Transport,
                SchFees = (float)e.SchFees,
                OtherExp = (float)e.OtherExp,
                LoanInst = (float)e.LoanInstalments,
                CreditPay = (float)e.CreditPay,

            };
        }

        internal static ExpenseEntity ToExpenseEntity(Expense expense)
        {
            return new ExpenseEntity
            {
                CustomerID = expense.CustomerId,
                ExpenseID = expense.ExpenseId,
                ExpenseName = expense.ExpenseName,
                ExpenseValue = expense.ExpenseValue,
                Food = expense.Food,
                HouseExp = expense.HouseExp,
                Transport = expense.Transport,
                SchFees = expense.SchFees,
                OtherExp = expense.OtherExp,
                LoanInstalments = expense.LoanInst,
                CreditPay = expense.CreditPay,

            };
        }

        #endregion



        #region Income
        internal static Income ToIncomeObject(IncomeEntity i)
        {

            return new Income
            {
                IncomeId = i.IncomeID,
                IncomeValue = (float)i.Income1,
                SpousesIncome = (float)i.SpouseIncome,
                OtherIncome = (float)i.OtherIncome,
                Savings = (float)i.Savings,
                CustomerId = i.CustomerID,


            };
        }

        internal static IncomeEntity ToIncomeEntity(Income income)
        {
            return new IncomeEntity
            {
                IncomeID = income.IncomeId,
                Income1 = (float)income.IncomeValue,
                SpouseIncome = (float)income.SpousesIncome,
                OtherIncome = (float)income.OtherIncome,
                Savings = (float)income.Savings,
                CustomerID = income.CustomerId,

            };
        }

        #endregion



        #region Liabilities
        internal static Liability ToLiabilityObject(LiabilityEntity l)
        {

            return new Liability
            {
                CustomerId = l.CustomerID,
                LiabilityId = l.LiabilityID,
                UnProLoans = (float)l.UnProLoans,
                Others = (float)l.Others


            };
        }

        internal static LiabilityEntity ToLiabilityEntity(Liability liability)
        {
            return new LiabilityEntity
            {
                CustomerID = liability.CustomerId,
                LiabilityID = liability.LiabilityId,
                UnProLoans = liability.UnProLoans,
                Others = liability.Others

            };
        }

        #endregion


        #region Messages
        internal static Message ToMessageObject(MessageEntity messageEntity, UserTypeEntity userTypeEntity, BranchEntity branchEntity, string messageType)
        {

            return new Message
            {
                Message_ID = messageEntity.MessageId,
                MessageBody = messageEntity.MessageBody,
                Created = messageEntity.Created,
                CreatedBy = messageEntity.CreatedBy,
                Modified = messageEntity.LastUpdated,
                ModifiedBy = messageEntity.ModifiedBy,
                SoCodeId = messageEntity.SoCodeId,
                MessageFromUserTypeID = messageEntity.MessageFromUserTypeID,
                UserTypeId = messageEntity.UserTypeId,
                NodeId = messageEntity.NodeId,
                Branch = branchEntity.BranchName,
                UserType = userTypeEntity.UserTypeName,
                MessageType = messageType,
                //UserTypename=messageEntity.UserTypeEntity.UserTypeName
            };
        }
        internal static Message ToMessageObject(MessageEntity messageEntity)
        {

            return new Message
            {
                UserTypename = messageEntity.UserTypeEntity.UserTypeName,
                MessageType = GetMessageType(messageEntity.UserTypeId),
                BranchName = GetBranchName(messageEntity.UserTypeId, messageEntity.NodeId),
                SoCodeId = messageEntity.SoCodeId,
                MessageBody = messageEntity.MessageBody,

                Message_ID = messageEntity.MessageId,
                Created = messageEntity.Created,
                CreatedBy = messageEntity.CreatedBy,
                Modified = messageEntity.Modified,
                ModifiedBy = messageEntity.ModifiedBy,
                MessageFromUserTypeID = messageEntity.MessageFromUserTypeID,
                UserTypeId = messageEntity.UserTypeId,
                NodeId = messageEntity.NodeId,

            };
        }
        internal static MessageEntity ToMessageEntity(Message msg)
        {
            return new MessageEntity
            {
                MessageId = (short)msg.Message_ID,
                MessageBody = msg.MessageBody,
                Created = msg.Created,
                CreatedBy = msg.CreatedBy,
                Modified = msg.Modified,
                ModifiedBy = msg.ModifiedBy,
                SoCodeId = msg.SoCodeId,
                MessageFromUserTypeID = (short)msg.MessageFromUserTypeID,
                UserTypeId = (short)msg.UserTypeId,
                NodeId = (short)msg.NodeId,
            };
        }

        #endregion


        #region Unit
        internal static SalesOneUnit ToUnitObject(UnitEntity u)
        {

            return new SalesOneUnit
            {
                UnitId = u.UnitId,
                BranchId = u.BranchId,
                Code = u.UnitCode,
                Name = u.UnitName,
                From = u.EffectiveFrom.ToShortDateString(),
                To = u.EffectiveTo.ToShortDateString()

            };
        }

        internal static UnitEntity ToUnitEntity(SalesOneUnit unit)
        {
            return new UnitEntity
            {

                UnitId = unit.UnitId,
                BranchId = (short)unit.BranchId,
                UnitCode = unit.Code,
                UnitName = unit.Name,
                EffectiveFrom = Convert.ToDateTime(unit.From),
                EffectiveTo = Convert.ToDateTime(unit.To)

            };
        }

        #endregion



        #region Asset
        internal static Asset ToAssetObject(AssetEntity ast)
        {

            return new Asset
            {

                AssetId = ast.AssetID,
                CustomerId = ast.CustomerID,
                AssetName = ast.AssetName,
                AssetValue = (float)ast.AssetValue,
                FixedDepo = (float)ast.FixedDepo,
                Saving = (float)ast.Savings,
                OthCeyIns = (float)ast.OthCeyInsu,
                OthIns = (float)ast.OthInsu,
                Others = (float)ast.Others,

            };
        }

        internal static AssetEntity ToAssetEntity(Asset asset)
        {
            return new AssetEntity
            {

                AssetID = asset.AssetId,
                CustomerID = asset.CustomerId,
                AssetName = asset.AssetName,
                AssetValue = asset.AssetValue,
                FixedDepo = asset.FixedDepo,
                Savings = asset.Saving,
                OthCeyInsu = asset.OthCeyIns,
                OthInsu = asset.OthIns,
                Others = asset.Others,
            };
        }

        #endregion



        #region Customer
        internal static Customer ToCustomerObject(CustomerEntity cs)
        {


            return new Customer
            {


                CustomerId = cs.CustomerID,
                FirstName = cs.FirstName,
                LastName = cs.LastName,
                Status = cs.Status,
                IdNumber = cs.IDNumber,
                IdType = cs.IDType == null ? String.Empty : cs.IDTypeEntity.Description,
                DOB = cs.DOB == null ? string.Empty : cs.DOB.Value.ToShortDateString(),
                ContactNo = cs.ContractNo,
                MaritalStatus = cs.MaritalStatus == null ? String.Empty : cs.MaritalStatusEntity.Description,
                Profession = cs.Profession,
                Country = cs.Country == null ? String.Empty : cs.CountryEntity.Description,
                State = cs.State,
                OtherName = cs.OtherName,
                HomeTelephone = cs.HomeTelephone,
                OfficialTelephone = cs.OfficeTelephone,
                EMail = cs.Email,
                Mobile = cs.Mobile,
                Address1 = cs.Address1,
                Address2 = cs.Address2,
                City = cs.City,
                Gender = cs.Gender,
                Remarks = cs.Remarks,
                LastUpdated = cs.LastUpdated == null ? string.Empty : cs.LastUpdated.Value.ToShortDateString(), 
                Title = cs.Title == null ? String.Empty : cs.SalutationEntity.Description.ToString(),
                BranchId = cs.BranchId == null ? 0 : (int)cs.BranchId,
                SoCode = cs.SOCode == null ? "System" : cs.SOCode,
                PrefNo = cs.PrefNo,
                PrefPlace = cs.PrefPlace
                
                



            };
        }

        internal static CustomerEntity ToCustomerEntity(Customer customer)
        {
            return new CustomerEntity
            {

                CustomerID = customer.CustomerId,
                FirstName = customer.FirstName,
                LastName = customer.LastName,
                Status = customer.Status,
                IDNumber = customer.IdNumber,
                IDType = customer.IdType != "" ? (int?)int.Parse(customer.IdType):null,
                DOB = customer.DOB != "" ? (DateTime?)Convert.ToDateTime(customer.DOB) : null,
                ContractNo = customer.ContactNo,
                MaritalStatus = customer.MaritalStatus != "" ? (int?)int.Parse(customer.MaritalStatus) : null,               
                Profession = customer.Profession,
                Country = customer.Country != "" ? (int?)int.Parse(customer.Country) : null,                     
                State = customer.State,
                OtherName = customer.OtherName,
                HomeTelephone = customer.HomeTelephone,
                OfficeTelephone = customer.OfficialTelephone,
                Email = customer.EMail,
                Mobile = customer.Mobile,
                Address1 = customer.Address1,
                Address2 = customer.Address2,
                City = customer.City,
                Gender = customer.Gender,
                Remarks = customer.Remarks,
                SOCode = customer.SoCode,
                BranchId = (int?)customer.BranchId, 
                LastUpdated = customer.LastUpdated != "" ? (DateTime?)Convert.ToDateTime(customer.LastUpdated) : null,
                
            };
        }

        #endregion



        #region Dependant
        internal static Dependant ToDependantObject(DependentEntity dp)
        {

            return new Dependant
            {

                DependantId = dp.DependentID,
                CustomerId = dp.CustomerID,
                Name = dp.Name,
                DependentType = dp.DependentType,
                DOB = dp.DOB == null ? string.Empty : dp.DOB.Value.ToShortDateString(),
                Gender = dp.Gender,                
                Remarks = dp.Reamrks

            };
        }

        internal static DependentEntity ToDependantEntity(Dependant dependent)
        {
            return new DependentEntity
            {

                DependentID = dependent.DependantId,
                CustomerID = dependent.CustomerId,
                Name = dependent.Name,
                DOB = Convert.ToDateTime(dependent.DOB),
                Gender = dependent.Gender,
                DependentType = dependent.DependentType,
                Reamrks = dependent.Remarks

            };
        }


        internal static NaDependent ToNaDependantObject(NADependentEntity dp)
        {

            return new NaDependent
            {

                NeedsAnNo = dp.NeedsAnalysisNo,
                DependantId = dp.DependentId,
                SoCode = dp.SOCode,
                Name = dp.Name,
                DOB = dp.DOB == null ? string.Empty : dp.DOB.Value.ToShortDateString(),
                Gender = dp.Gender,
                DependentType = dp.DependentType,
                Remarks = dp.Remarks

            };
        }


        #endregion



        #region User
        internal static UserInformation ToUserInfoObject(int? groupId, string groupName, int? branchId, string branchName, int? unitId, string unitName, int userType, int nodeId)
        {
            return new UserInformation
            {
                UnitId = unitId,
                UnitName = unitName,
                BranchId = branchId,
                BranchName = branchName,
                GroupId = groupId,
                GroupName = groupName,
                UserType = userType,
                NodeId = nodeId

            };
        }

        internal static User ToUserObject(UserEntity userEntity, UsersInStructureEntity struc)
        {

            return new User
            {
                UserId = userEntity.UserId,
                UserName = userEntity.aspnet_User.UserName,
                Address1 = userEntity.Address1,
                Address2 = userEntity.Address2,
                City = userEntity.City,
                Contact = userEntity.ContactNo,
                Country = userEntity.Country == null ? String.Empty : userEntity.CountryEntity.Description,
                Gender = userEntity.Gender,
                IdNo = userEntity.IdNo,
                IdType = userEntity.IdType == null ? String.Empty : userEntity.IDTypeEntity.Description,
                Name = userEntity.Name,
                LastUpBy = userEntity.aspnet_User1.UserName == null ? String.Empty : userEntity.aspnet_User1.UserName,
                LastUpdateDate = userEntity.LastUpdated == null ? string.Empty : userEntity.LastUpdated.Value.ToShortDateString(),
                PostalCode = userEntity.PostalCode,
                UserType = struc.UserTypeId,
                NodeId = struc.NodeId,
                SoCode = userEntity.SOCode





            };
        }

        internal static User ToUserObject(UserEntity userEntity)
        {

            return new User
            {
                UserId = userEntity.UserId,
                UserName = userEntity.aspnet_User.UserName,
                Address1 = userEntity.Address1,
                Address2 = userEntity.Address2,
                City = userEntity.City,
                Contact = userEntity.ContactNo,
                Country = userEntity.Country == null ? String.Empty : userEntity.CountryEntity.Description,
                Gender = userEntity.Gender,
                IdNo = userEntity.IdNo,
                IdType = userEntity.IdType == null ? String.Empty : userEntity.IDTypeEntity.Description,
                Name = userEntity.Name,
                LastUpBy = userEntity.aspnet_User1.UserName == null ? String.Empty : userEntity.aspnet_User1.UserName,
                LastUpdateDate = userEntity.LastUpdated == null ? string.Empty : userEntity.LastUpdated.Value.ToShortDateString(),
                PostalCode = userEntity.PostalCode,
                SoCode = userEntity.SOCode,
                IsDeleted = userEntity.IsDeleted == null ? false : Convert.ToBoolean((bool?)userEntity.IsDeleted),
                DoneBy = userEntity.DoneBy
                
                




            };
        }

        internal static UserEntity ToUserEntity(User user)
        {
            return new UserEntity
            {

                UserId = user.UserId,
                Address1 = user.Address1,
                Address2 = user.Address2,
                City = user.City,
                ContactNo = user.Contact,
                Country =  (int?)Convert.ToInt32(user.Country),
                Gender = user.Gender,
                IdNo = user.IdNo,
                IdType = (int?)Convert.ToInt32(user.IdType),
                Name = user.Name,
                UpdatedBy =  new Guid(user.LastUpBy),
                LastUpdated = Convert.ToDateTime(user.LastUpdateDate),
                PostalCode = user.PostalCode,
                SOCode = user.SoCode,
                IsDeleted = user.IsDeleted,
                DoneBy = user.DoneBy
            };
        }

        #endregion



        #region Prospect
        internal static Prospect ToProspectObject(ProspectEntity p)
        {

            return new Prospect
            {
                ProspectId = p.ProspectID,
                CustomerId = p.CustomerID,
                SOCode = p.SOCode

            };
        }

        internal static ProspectEntity ToProspectEntity(Prospect prospect)
        {
            return new ProspectEntity
            {
                ProspectID = prospect.ProspectId,
                CustomerID = prospect.CustomerId,
                SOCode = prospect.SOCode

            };
        }

        #endregion



        #region Suspect
        internal static Suspect ToSuspectObject(SuspectEntity s)
        {

            return new Suspect
            {
                SuspectId = s.SuspectID,
                CustomerId = s.CustomerID,
                SOCode = s.SOCode

            };
        }

        internal static SuspectEntity ToSuspectEntity(Suspect suspect)
        {
            return new SuspectEntity
            {
                SuspectID = suspect.SuspectId,
                CustomerID = suspect.CustomerId,
                SOCode = suspect.SOCode


            };
        }

        #endregion



        #region Spouse
        internal static Spouse ToSpouseObject(SpouseEntity sp)
        {

            return new Spouse
            {

                SpouseId = sp.SpouseID,
                CustomerId = sp.CustomerID,
                IdType = sp.IDTypeEntity == null ? string.Empty : sp.IDTypeEntity.Description == null ? string.Empty : sp.IDTypeEntity.Description,
                Salutation = sp.SalutationEntity == null ? string.Empty : sp.SalutationEntity.Description == null ? string.Empty : sp.SalutationEntity.Description,
                Initial = sp.Initial,
                Surname = sp.Surname,
                OtherName = sp.OtherName,
                DOB = sp.DOB == null ? string.Empty : sp.DOB.Value.ToShortDateString(),
                Gender = sp.Gender,
                Profession = sp.Profession,

            };
        }

        internal static SpouseEntity ToSpouseEntity(Spouse spouse)
        {
            return new SpouseEntity
            {
                SpouseID = spouse.SpouseId,
                CustomerID = spouse.CustomerId,
                IDType = Convert.ToInt32(spouse.IdType),
                IDNo = spouse.IdNo,
                Salutation = Convert.ToInt32(spouse.Salutation),
                Initial = spouse.Initial,
                Surname = spouse.Surname,
                OtherName = spouse.OtherName,
                DOB = Convert.ToDateTime(spouse.DOB),
                Gender = spouse.Gender,
                Profession = spouse.Profession,

            };
        }

        #endregion



        #region MessageTypes
        internal static MessageType ToMessageTypeObject(MessageTypeEntity messageType)
        {

            return new MessageType
            {
                MessageTypeId = messageType.MessageTypeID,
                MessageTypeName = messageType.MessageTypeName
            };
        }

        internal static MessageTypeEntity ToMessageTypeEntity(MessageType messageType)
        {
            return new MessageTypeEntity
            {
                MessageTypeID = (short)messageType.MessageTypeId,
                MessageTypeName = messageType.MessageTypeName
            };
        }

        #endregion


        #region UserRole(RolesInUserType)
        internal static UserRole ToUserRoleObject(RolesInUserTypeEntity rolesInUserTypeEntity)
        {

            return new UserRole
            {
                RoleId = rolesInUserTypeEntity.RoleId,
                UserTypeId = rolesInUserTypeEntity.UserTypeId,
                Status = rolesInUserTypeEntity.Status
            };
        }

        internal static RolesInUserTypeEntity ToUserRoleEntity(UserRole userRole)
        {
            return new RolesInUserTypeEntity
            {
                RoleId = userRole.RoleId,
                UserTypeId = userRole.UserTypeId,
                Status = userRole.Status
            };
        }

        #endregion


        #region UserRole(aspnet_Roles)
        internal static UserRole_aspnet ToAsp_netUserRoleObject(aspnet_RoleEntity _aspnet_RoleEntity)
        {

            return new UserRole_aspnet
            {
                RoleId = _aspnet_RoleEntity.RoleId,
                RoleName = _aspnet_RoleEntity.RoleName,
                ApplicationId = _aspnet_RoleEntity.ApplicationId,
                LoweredRoleName = _aspnet_RoleEntity.LoweredRoleName,
                Description = _aspnet_RoleEntity.Description,
                IsEnabled = _aspnet_RoleEntity.IsEnabled

            };
        }

        internal static aspnet_RoleEntity ToAsp_netRoleEntity(UserRole_aspnet userRole_aspnet)
        {
            return new aspnet_RoleEntity
            {
                RoleId = userRole_aspnet.RoleId,
                RoleName = userRole_aspnet.RoleName,
                ApplicationId = userRole_aspnet.ApplicationId,
                LoweredRoleName = userRole_aspnet.LoweredRoleName,
                Description = userRole_aspnet.Description,
                IsEnabled = userRole_aspnet.IsEnabled
            };
        }

        #endregion


        #region Tasks
        internal static Task ToTaskObject(TaskEntity taskEntity)
        {

            return new Task
            {
                TaskId = taskEntity.TaskId,
                TaskName = taskEntity.TaskName,
                Url = taskEntity.Url
            };
        }

        internal static TaskEntity ToMessageTypeEntity(Task task)
        {
            return new TaskEntity
            {
                TaskId = (short)task.TaskId,
                TaskName = task.TaskName,
                Url = task.Url
            };
        }

        #endregion


        #region Pages
        internal static Page ToPageObject(PagesInTaskEntity pagesInTaskEntity)
        {

            return new Page
            {
                TaskId = pagesInTaskEntity.TaskId,
                PageId = pagesInTaskEntity.PageId,
                Url = pagesInTaskEntity.PageURL,
                Title = pagesInTaskEntity.PageTitle
            };
        }

        internal static PagesInTaskEntity ToPageEntity(Page page)
        {
            return new PagesInTaskEntity
            {
                TaskId = (short)page.TaskId,
                PageTitle = page.Title,
                PageURL = page.Url
            };
        }

        #endregion


        #region Modules
        internal static Module ToModuleObject(ModuleEntity moduleEntity)
        {

            return new Module
            {
                ModuleId = moduleEntity.ModuleId,
                ModuleName = moduleEntity.ModuleName
            };
        }

        internal static ModuleEntity ToModuleEntity(Module module)
        {
            return new ModuleEntity
            {
                ModuleId = (short)module.ModuleId,
                ModuleName = module.ModuleName
            };
        }

        #endregion


        //#region Task Permissions
        //internal static TaskPermission ToTaskPermissionObject(TaskPermissionEntity taskPermissionEntity)
        //{

        //    return new TaskPermission
        //    {
        //        TaskId = taskPermissionEntity.TaskId,
        //        RoleId=taskPermissionEntity.RoleId,
        //        Permissions=taskPermissionEntity.Permissions
        //    };
        //}

        //internal static TaskPermissionEntity ToTaskPermissionEntity(TaskPermission taskPermission)
        //{
        //    return new TaskPermissionEntity
        //    {
        //        TaskId = taskPermission.TaskId,
        //       RoleId=taskPermission.RoleId,
        //       Permissions=taskPermission.Permissions
        //    };
        //}

        //#endregion


        #region SalesActivity
        internal static SalesAppoinments ToActivityObject(SalesActivityPolicyEntity sa)
        {
            return new SalesAppoinments
            {

                ContractID = sa.ContractId,
                ApptDate = sa.ApptDate,
                SOCode = sa.SOCode,
                SCRemark = sa.SCRemark

            };
        }

        internal static SalesActivityPolicyEntity ToActivityEntity(SalesAppoinments activity)
        {
            return new SalesActivityPolicyEntity
            {
                ContractId = activity.ContractID.ToString(),
                ApptDate = activity.ApptDate,
                SOCode = activity.SOCode,
                SCRemark = activity.SCRemark
            };
        }

        internal static ActivityRemark ToActivityRemarkObject(SalesActivityRemarkEntity sa)
        {
            if (sa == null)
                return null;
            return new ActivityRemark
            {
                Date = sa.Date,
                SOCode = sa.SOCode,
                Remark = sa.Remark

            };
        }

        internal static ActivityRemark ToActivityRemarkObject(SalesActivityProspectEntity sa)
        {
            if (sa == null)
                return null;
            return new ActivityRemark
            {
                Date = sa.ApptDate,
                SOCode = sa.SOCode,
                Remark = sa.SCRemark

            };
        }

        internal static SalesActivityRemarkEntity ToActivityRemarkEntity(ActivityRemark activity)
        {
            return new SalesActivityRemarkEntity
            {

                Date = activity.Date,
                SOCode = activity.SOCode,
                Remark = activity.Remark
            };
        }
        #endregion




        #region Code Type



        #region Country


        internal static Country ToCodeObject(CountryEntity cce)
        {
            if (cce == null)
            {
                return null;
            }

            return new Country
            {


                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,


            };

        }

        internal static CountryEntity ToCodeEntity(Country c)
        {
            return new CountryEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion





        #region ClaimStatus
        internal static ClaimStatus ToCodeObject(ClaimStatusEntity cce)
        {

            return new ClaimStatus
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static ClaimStatusEntity ToCodeEntity(ClaimStatus c)
        {
            return new ClaimStatusEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion




        #region CompaintSubType
        internal static CompaintSubType ToCodeObject(CompaintSubTypeEntity cce)
        {

            return new CompaintSubType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static CompaintSubTypeEntity ToCodeEntity(CompaintSubType c)
        {
            return new CompaintSubTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region CompetionType
        internal static CompetionType ToCodeObject(CompetionTypeEntity cce)
        {

            return new CompetionType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static CompetionTypeEntity ToCodeEntity(CompetionType c)
        {
            return new CompetionTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region ComplaintStatus
        internal static ComplaintStatus ToCodeObject(ComplaintStatusEntity cce)
        {

            return new ComplaintStatus
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static ComplaintStatusEntity ToCodeEntity(ComplaintStatus c)
        {
            return new ComplaintStatusEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region ComplaintType
        internal static ComplaintType ToCodeObject(ComplaintTypeEntity cce)
        {

            return new ComplaintType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static ComplaintTypeEntity ToCodeEntity(ComplaintType c)
        {
            return new ComplaintTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region IDType
        internal static IDType ToCodeObject(IDTypeEntity cce)
        {

            return new IDType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static IDTypeEntity ToCodeEntity(IDType c)
        {
            return new IDTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region InformationType
        internal static InformationType ToCodeObject(InformationTypeEntity cce)
        {

            return new InformationType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static InformationTypeEntity ToCodeEntity(InformationType c)
        {
            return new InformationTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion


        #region MaritalStatus
        internal static MaritalStatus ToCodeObject(MaritalStatusEntity cce)
        {

            return new MaritalStatus
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static MaritalStatusEntity ToCodeEntity(MaritalStatus c)
        {
            return new MaritalStatusEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region Measure
        internal static Measure ToCodeObject(MeasureEntity cce)
        {

            return new Measure
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static MeasureEntity ToCodeEntity(Measure c)
        {
            return new MeasureEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region Month
        internal static Month ToCodeObject(MonthEntity cce)
        {

            return new Month
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static MonthEntity ToCodeEntity(Month c)
        {
            return new MonthEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region PaymentMode
        internal static PaymentMode ToCodeObject(PaymentModeEntity cce)
        {

            return new PaymentMode
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static PaymentModeEntity ToCodeEntity(PaymentMode c)
        {
            return new PaymentModeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region PendingRequirement
        internal static PendingRequirement ToCodeObject(PendingRequirementEntity cce)
        {

            return new PendingRequirement
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static PendingRequirementEntity ToCodeEntity(PendingRequirement c)
        {
            return new PendingRequirementEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion




        #region PendingStatus
        internal static PendingStatus ToCodeObject(PendingStatusEntity cce)
        {

            return new PendingStatus
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static PendingStatusEntity ToCodeEntity(PendingStatus c)
        {
            return new PendingStatusEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion




        #region PolicyStatus
        internal static PolicyStatus ToCodeObject(PolicyStatusEntity cce)
        {

            return new PolicyStatus
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static PolicyStatusEntity ToCodeEntity(PolicyStatus c)
        {
            return new PolicyStatusEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion




        #region Policy Type
        internal static PolicyType ToCodeObject(PolicyTypeEntity cce)
        {

            return new PolicyType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static PolicyTypeEntity ToCodeEntity(PolicyType c)
        {
            return new PolicyTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion



        #region Salutation
        internal static Salutation ToCodeObject(SalutationEntity cce)
        {

            return new Salutation
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static SalutationEntity ToCodeEntity(Salutation c)
        {
            return new SalutationEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion


        #region SOTypes
        internal static SOType ToCodeObject(SOTypeEntity cce)
        {

            return new SOType
            {
                CodeId = cce.Code_Id,
                Code = cce.Code,
                Description = cce.Description,

            };
        }

        internal static SOTypeEntity ToCodeEntity(SOType c)
        {
            return new SOTypeEntity
            {
                Code_Id = c.CodeId,
                Code = c.Code,
                Description = c.Description,

            };
        }

        #endregion
        #endregion




        #region ProspectQuotations
        internal static ProspectQuotations ToProspectQuotatationsObject(ProspectQuotationEntity pq)
        {

            return new ProspectQuotations
            {

                QuotationNo = pq.QuotationNo,
                SOCode = pq.SOCode,
                ProspectId = pq.ProspectId,
                PlanCode = pq.PlanCode,
                //RecStatus = (char)pq.Rec_Status,
                //LastUpdatedTimeStamp = pq.LastUpdated.Value.ToShortDateString(),
                LastUpdated = pq.LastUpdated == null ? string.Empty : pq.LastUpdated.Value.ToShortDateString(),
                Dob = pq.Dob.ToString(),
                Initials = pq.Initials,
                Surname = pq.Surname,
                Title = pq.Title,
                Gender = pq.Gender,


            };
        }

        internal static ProspectQuotationEntity ToProspectQuotatationsEntity(ProspectQuotations quotations)
        {
            return new ProspectQuotationEntity
            {
                QuotationNo = quotations.QuotationNo,
                SOCode = quotations.SOCode,
                ProspectId = quotations.ProspectId,
                PlanCode = quotations.PlanCode,
                //Rec_Status = quotations.RecStatus,
                LastUpdated = Convert.ToDateTime(quotations.LastUpdated),
                Dob = Convert.ToDateTime(quotations.Dob),
                Gender = quotations.Gender,
                Initials = quotations.Initials,
                Surname = quotations.Surname,
                Title = quotations.Title,



            };
        }

        #endregion




        internal static string GetBranchName(int userTypeId, int nodeId)
        {
            LinqBranch branch = new LinqBranch();
            if (userTypeId == 2 || userTypeId == 1)
            {
                return "All Branches";
            }
            else if (userTypeId == 3)
            {

                return branch.GetBranch(nodeId).BranchName;
            }
            else if (userTypeId == 4)
            {
                return branch.GetBranchForUnit(nodeId).BranchName;
            }
            return "";
        }


        internal static string GetMessageType(int userTypeId)
        {
            if (userTypeId == 1)
                return "Broadcast";
            else
                return "Individual";

        }

        #region Securiry

        internal static TaskCredentials ToTaskPermissionObject(TaskPermissionEntity perm)
        {

            return new TaskCredentials
            {
                RoleId = perm.RoleId,
                TaskId = perm.TaskId,
                Credentials = perm.Permissions
            };
        }

        internal static TaskPermissionEntity ToTaskPermissionEntity(TaskCredentials perm)
        {
            return new TaskPermissionEntity
            {
                RoleId = perm.RoleId,
                TaskId = perm.TaskId,
                Permissions = perm.Credentials
            };
        }

        #endregion


        #region ProductCategory


        internal static Product ToProductObject(ProductEntity pe)
        {

            return new Product
            {



                ProductDescription = pe.ProductDescription,
                MonthlyMode = pe.QuoPlanEntity.MonthlyMode,
                QuarterlyMode = pe.QuoPlanEntity.QuarterlyMode,
                HalfYearlyMode = pe.QuoPlanEntity.HalfYearlyMode,
                YearlyMode = pe.QuoPlanEntity.YearlyMode,
                SingleMode = pe.QuoPlanEntity.SingleMode,
                PlanMinAge = pe.QuoPlanEntity.PlanMinAge,
                PlanMaxAge = pe.QuoPlanEntity.PlanMaxAge,
                PlanMinTerm = pe.QuoPlanEntity.PlanMinTerm,
                PlanMaxTerm = pe.QuoPlanEntity.PlanMaxTerm,
                PlanMinPremium = (float)pe.QuoPlanEntity.PlanMinPremium,
                PlanMaxPremium = (float)pe.QuoPlanEntity.PlanMaxPremium,
                PlanReport = pe.QuoPlanEntity.PlanReport,
                ProductFile = pe.ProductFile,
                RootCategoryCode = pe.RootCategoryCode,
                LastUpdated = pe.LastUpdated,
                ProductParentCategory = pe.ProductCategoryEntity.ProductParentCategoryCode,
                CategoryCodeExtension = pe.ProductCategoryEntity.CategoryCodeExtension,
                ShortName = pe.ProductCategoryEntity.CategoryShortName,
                CategoryLevel = pe.ProductCategoryEntity.CategoryLevelCode,
                CategoryPath = pe.ProductCategoryEntity.CategoryPath,
                Status = pe.QuoPlanEntity.Status.ToLower() == "a" ? "ACTIVE" : "INACTIVE",
                PlanName = pe.PlanName,
                PlanCode = pe.PlanCode,
                ProductCategoryCode = pe.ProductCategoryEntity.ProductCategoryCode,
                ProductCategoryName = pe.ProductCategoryEntity.ProductCategoryName,

            };

        }

        internal static ProductEntity ToProductEntity(Product p1)
        {
            return new ProductEntity
            {
                PlanCode = p1.PlanCode,
                PlanName = p1.PlanName,
                ProductFile = p1.ProductFile,
                ProductCategoryCode = (int)p1.ProductCategoryCode,
                ProductDescription = p1.ProductDescription,
                RootCategoryCode = (int)p1.RootCategoryCode,
                LastUpdated = (DateTime)p1.LastUpdated,
            };
        }

        internal static QuoPlanEntity ToQuoPlanEntity(Product p1)
        {
            return new QuoPlanEntity
            {
                PlanCode = p1.PlanCode,
                Status = p1.Status,
                MonthlyMode = p1.MonthlyMode,
                QuarterlyMode = p1.QuarterlyMode,
                HalfYearlyMode = p1.HalfYearlyMode,
                YearlyMode = p1.YearlyMode,
                SingleMode = p1.SingleMode,
                PlanMaxAge = (short)p1.PlanMaxAge,
                PlanMinAge = (short)p1.PlanMinAge,
                PlanMaxPremium = (decimal)p1.PlanMaxPremium,
                PlanMinPremium = (decimal)p1.PlanMinPremium,
                PlanMaxTerm = (short)p1.PlanMaxTerm,
                PlanMinTerm = (short)p1.PlanMinTerm,
                PlanReport = p1.PlanReport,
                LastUpdated = p1.LastUpdated,
            };
        }


        internal static ProductCategoryEntity ToProductCategoryEntity(Product p1)
        {
            return new ProductCategoryEntity
            {
                ProductCategoryCode = (int)p1.ProductCategoryCode,
                ProductCategoryName = p1.ProductCategoryName,
                ProductParentCategoryCode = (int)p1.ProductParentCategory,
                CategoryCodeExtension = p1.CategoryCodeExtension,
                CategoryShortName = p1.ShortName,
                CategoryLevelCode = (int)p1.CategoryLevel,
                CategoryPath = p1.CategoryPath,
                LastUpdated = (DateTime)p1.LastUpdated,

            };
        }

        #endregion

        #region Benefit


        internal static QuoLifeBenefit ToBenefitObject(QuoLifeBenefitEntity qlbe)
        {
            if (qlbe == null)
            {
                return null;
            }

            return new QuoLifeBenefit
            {
                BenefitCode = qlbe.BenefitCode,
                BenefitName = qlbe.BenefitName,
                BenefitExpireStatus = qlbe.BenefitExpireStatus,
                PdSt = qlbe.PdSt,
                PmSt = qlbe.PmSt,
                IbrvSt = qlbe.IbrvSt,
                DefendentGrp = qlbe.DependentGrp,
                LastUpdated = qlbe.LastUpdated,

            };

        }

        internal static QuoLifeBenefitEntity ToBenefitEntity(QuoLifeBenefit qlb)
        {
            return new QuoLifeBenefitEntity
            {
                BenefitCode = qlb.BenefitCode,
                BenefitName = qlb.BenefitName,
                BenefitExpireStatus = qlb.BenefitExpireStatus,
                PdSt = qlb.PdSt,
                PmSt = qlb.PmSt,
                IbrvSt = qlb.IbrvSt,
                DependentGrp = qlb.DefendentGrp,
                LastUpdated = qlb.LastUpdated,

            };
        }



        #endregion

        #region ProductCategoryCode


        internal static ProductCategory ToProductCategoryObject(ProductCategoryEntity pce)
        {

            return new ProductCategory
            {
                ProductCategoryCode = pce.ProductCategoryCode,
                ProductCategoryName = pce.ProductCategoryName,

            };

        }

        internal static ProductCategoryEntity ToProductCategoryEntity(ProductCategory pc)
        {
            return new ProductCategoryEntity
            {
                ProductCategoryCode = pc.ProductCategoryCode,
                ProductCategoryName = pc.ProductCategoryName,

            };
        }

        #endregion

        #region Quotation Details
        internal static QuotationDetails ToQuotatioDetailsObject(QuoDetailEntity qd)
        {

            return new QuotationDetails
            {

                QuotationNo = qd.QuotationNo,
                BenefitCode = qd.BenefitCd,
                Life = qd.Life,
                Term = (int)qd.Term,
                PdPm = (float)qd.Pdpm,
                SumAssured = (float)qd.SumAssured,
                //RecStatus = qd.RecStatus.ToString(),
                //LastUpdatedTimeStamp = qd.LastUpdated.ToString(),
                Socode = qd.SOCode,
                PayMode = qd.PayMode,
                Premium = (float)qd.Premium



            };
        }



        #endregion

        #region BatchJob
        internal static BatchJob ToBatchJobObject(SqlDataReader rd)
        {
            return new BatchJob
            {
                ActiveEndDate = (int)rd["active_end_date"],
                ActiveStartDate = (int?)rd["active_start_date"],
                ActiveStartTime = (int)rd["active_start_time"],
                Enabled = Convert.ToInt16(rd["enabled"]),
                FreqInterval = (int)rd["freq_interval"],
                FreqRecurrenceFactor = (int)rd["freq_recurrence_factor"],
                FreqRelativeInterval = (int)rd["freq_relative_interval"],
                FreqSubdayInterval = (int)rd["freq_subday_interval"],
                FreqSubdayType = (int)rd["freq_subday_type"],
                FreqType = (int)rd["freq_type"],
                ActiveEndTime = (int)rd["active_end_time"]
            };
        }

        internal static Emails ToEmailObject(EmailsEntity eme)
        {


            return new Emails
            {
                JobId = eme.JobId,
                Email = eme.Emails,
                NumberOfDays = eme.NumberOfDays,

            };

        }

        internal static EmailsEntity ToEmailEntity(Emails e)
        {
            return new EmailsEntity
            {
                JobId = e.JobId,
                Emails = e.Email,
                NumberOfDays = e.NumberOfDays,

            };
        }




        #endregion

        #region Collection

        internal static CollectionTransaction ToCollectionTransactionObject(CollectionEntity collectionEntity)
        {
            
            return new CollectionTransaction
            {
                CSSNo = collectionEntity.CSSNo,
                SOCode = collectionEntity.SOCode,
                Status = (collectionEntity.CollectionStatus.ToLower() == "cancelledverified" ? "Cancelled" : (collectionEntity.CollectionStatus.ToLower() == "cancelledunprocessed" ? "Unprocessed" : collectionEntity.CollectionStatus)),
                LastSyncDate = (DateTime)collectionEntity.LastSyncDate,
                BranchCode = collectionEntity.BranchCode,
                VerifiedDate = collectionEntity.VerifiedDate.HasValue == false ? string.Empty : collectionEntity.VerifiedDate.Value.ToShortDateString(),

                ReceiptNo = collectionEntity.ReceiptSeqNo,
                ContractNo = collectionEntity.ContractNo,
                LoanInterest = collectionEntity.LoanInt,
                CollectionAmount = collectionEntity.CollectionAmt,
                CollectionType = collectionEntity.CollectionType,
                CheqNo = collectionEntity.ChequeNo,
                VerifiedBy = collectionEntity.VerifiedBy,
                BankedStatus =    collectionEntity.BankState,
                ClientID = collectionEntity.CustomerId,
                RemarksCashier = collectionEntity.RemarksCashier,
                RemarksSO = collectionEntity.Remarks,


                //IdNo = collectionEntity.CustomerIDNo,
                //IDType = (int)collectionEntity.CustomerIDType,
                //Address1 = collectionEntity.Address1,
                //Address2 = collectionEntity.Address2,
                //Address3 = collectionEntity.Address3,
                LastUpdatedDate = (DateTime)collectionEntity.LastUpdated,
                //CustomerName = collectionEntity.CustomerName,
                //PostCode = collectionEntity.PostalCode,
                //Signature = s,//(collectionEntity.Signature == null) ? null : ByteToStream((byte[])(collectionEntity.Signature).ToArray()),
                BankCode = collectionEntity.BankCode,
                ChangeLog = collectionEntity.ChangeLog
                //CheqeDate = (DateTime)collectionEntity.ChequeDate,

                //Gender = collectionEntity.Gender,
                //PrintCSS = (bool)collectionEntity.printCSS,
                //PrintReceipt = (bool)collectionEntity.PrintReceipt,
                //Reason = collectionEntity.Reason,
                //Rec_Status = (char)collectionEntity.Rec_Status,
                //ReceiptDate = (DateTime)collectionEntity.ReceiptDate,
                //Salutation = (int)collectionEntity.Salutation,
                //TxnSt = collectionEntity.TxnSt
            };


        }

        internal static CollectionEntity ToCollectionTransactionEntity(CollectionTransaction collectionTransaction)
        {
            return new CollectionEntity
            {

            };
        }

        //internal static List<CollectionEntity> ToCollectionTransactionEntity(IEnumerable<CollectionTransaction> collectionTransactions)
        //{
        //    List<CollectionEntity> CollectionEntityCollection = new List<CollectionEntity>();
        //    foreach (CollectionTransaction collectionTransaction in collectionTransactions)
        //    {
        //        CollectionEntity cloEntity = new CollectionEntity(); 
                
        //        cloEntity.BankState = collectionTransaction.BankedStatus;
        //        cloEntity.RemarksCashier = collectionTransaction.RemarksCashier;
        //        cloEntity.ContractNo = collectionTransaction.ContractNo;
        //        cloEntity.CustomerId = collectionTransaction.ClientID;
        //        cloEntity.LoanInt = collectionTransaction.LoanInterest;
        //        cloEntity.VerifiedBy = collectionTransaction.VerifiedBy;
        //        cloEntity.VerifiedDate = collectionTransaction.VerifiedDate;
        //        cloEntity.TxnSt = collectionTransaction.TxnSt;
        //        cloEntity.VerifiedBy = collectionTransaction.VerifiedBy;
        //        cloEntity.VerifiedDate = collectionTransaction.VerifiedDate;
        //        cloEntity.SOCode = collectionTransaction.SOCode;
        //        cloEntity.Signature = (collectionTransaction.Signature == null)? null:StreamToByte((collectionTransaction.Signature));
        //        cloEntity.Salutation = collectionTransaction.Salutation;
        //        cloEntity.ReceiptSeqNo = collectionTransaction.ReceiptNo;
        //        cloEntity.ReceiptDate = collectionTransaction.ReceiptDate;
        //        cloEntity.Rec_Status = collectionTransaction.Rec_Status;
        //        cloEntity.Reason = collectionTransaction.Reason;
        //        cloEntity.PrintReceipt = collectionTransaction.PrintReceipt;
        //        cloEntity.printCSS = collectionTransaction.PrintCSS;
        //        cloEntity.PostalCode = collectionTransaction.PostCode;
        //        cloEntity.PaymentMethod = collectionTransaction.PaymentMethod;
        //        cloEntity.LoanInt = collectionTransaction.LoanInterest;
        //        cloEntity.LastUpdated = collectionTransaction.LastUpdatedDate;
        //        cloEntity.LastSyncDate = collectionTransaction.LastSyncDate;
        //        cloEntity.Gender = collectionTransaction.Gender;
        //        cloEntity.DOB = collectionTransaction.DOB;
        //        cloEntity.CustomerName = collectionTransaction.CustomerName;
        //        cloEntity.CustomerIDType = collectionTransaction.IDType;
        //        cloEntity.CustomerIDNo = collectionTransaction.IdNo;
        //        cloEntity.CustomerId = collectionTransaction.ClientID;
        //        cloEntity.CSSNo = collectionTransaction.CSSNo;
        //        cloEntity.CollectionType = collectionTransaction.CollectionType;
        //        cloEntity.CollectionStatus = collectionTransaction.Status;
        //        cloEntity.CollectionAmt = collectionTransaction.CollectionAmount;
        //        cloEntity.CivilStatus = collectionTransaction.CivilStatus;
        //        cloEntity.ChequeNo = collectionTransaction.CheqeNo;
        //        cloEntity.ChequeDate = collectionTransaction.CheqeDate;
        //        cloEntity.BranchCode = collectionTransaction.BranchCode;
        //        cloEntity.BankCode = collectionTransaction.BankCode;
                

        //        CollectionEntityCollection.Add(cloEntity);
        //    }
        //    return CollectionEntityCollection;
        //}

        public static byte[] StreamToByte(Stream stream)
        {
            byte[] buffer = new byte[32768];
            using (MemoryStream ms = new MemoryStream())
            {
                while (true)
                {
                    int read = stream.Read(buffer, 0, buffer.Length);
                    if (read <= 0)
                        return ms.ToArray();
                    ms.Write(buffer, 0, read);
                }
            }
        }

        public static Stream ByteToStream(byte[] bytArr)
        {
            Stream s = new MemoryStream(bytArr);
            return s;
        }

        #endregion

        #region NeedsAnalysis


        internal static NeedsAnalysis ToNeedsAnalysisObject(NeedsAnalysisDetailEntity nade)
        {

            return new NeedsAnalysis
            {

                NeedAnalysisNo = nade.NeedsAnalysisNo,
                CustomerId = nade.CustomerID,
                
                CreatedDate = nade.LastUpdated == null ? string.Empty : nade.LastUpdated.ToShortDateString(),
                //nade.LastUpdated,
                SoCode = nade.SOCode,
                ProspectId = nade.CustomerID,
                //nade.CustomerEntity. ProspectEntities.FirstOrDefault().ProspectID, 
                //nade.CustomerEntity.ProspectEntities == null ? string.Empty : nade.CustomerEntity.ProspectEntities.FirstOrDefault().ProspectID,          
                Analyzes = nade.Analyzes == null ? 0 : (float)nade.Analyzes,
                ApSt = nade.ApprovalStatus == null ? 0 : (int)nade.ApprovalStatus,
                Assets = nade.TotalAssets == null ? 0 : (float)nade.TotalAssets,
                CritAmt = nade.CritcalAmt == null ? 0 : (float)nade.CritcalAmt,
                Dob = nade.DOB == null ? string.Empty : nade.DOB.Value.ToShortDateString(),
                Expenses = nade.TotalExpenses == null ? 0 : (float)nade.TotalExpenses,
                Gender = nade.Gender,
                Income = nade.TotalIncome == null ? 0 : (float)nade.TotalIncome,
                LastName = nade.LastName,
                Liability = nade.TotalLiability == null ? 0 : (float)nade.TotalLiability,
                Marital = nade.MaritalStatus == null ? string.Empty : nade.MaritalStatusEntity.Description,
                MinTerm = nade.MinTerm == null ? 0 : (int)nade.MinTerm,
                NeedAnOpt = nade.NeedsAnalysisOption == null ? 0 : (int)nade.NeedsAnalysisOption,
                ProtIn = nade.MinProIncome == null ? 0 : (float)nade.MinProIncome,
                Remarks = nade.Remarks,
                Rider = nade.Rider == null ? 0 : (float)nade.Rider,
                Sum = nade.BasicSum == null ? 0 : (float)nade.BasicSum,
                NoOfChild = nade.NoOfChilds == null ? 0 : (int)nade.NoOfChilds,

                //mapping tables
                //income
                Inc = nade.NAIncomeEntity == null ? 0 :  nade.NAIncomeEntity.Income == null ? 0 : (float)nade.NAIncomeEntity.Income ,
                SpouseIncome = nade.NAIncomeEntity == null ? 0 : nade.NAIncomeEntity.SpouseIncome == null ? 0 : (float)nade.NAIncomeEntity.SpouseIncome,
                OtherIncome = nade.NAIncomeEntity == null ? 0 : nade.NAIncomeEntity.OtherIncome == null ? 0 : (float)nade.NAIncomeEntity.OtherIncome,
                SavingInc = nade.NAIncomeEntity == null ? 0 :  nade.NAIncomeEntity.Savings == null ? 0 :(float)nade.NAIncomeEntity.Savings,

                //liabilities
                UnpLoans = nade.NALiabilityEntity == null ? 0 : (float)nade.NALiabilityEntity.UnProLoans,

                //expenses
                Food = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.Food == null ? 0 : (float)nade.NAExpenseEntity.Food,
                HouseExp = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.HouseExp == null ? 0 : (float)nade.NAExpenseEntity.HouseExp,
                Trans = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.Transport == null ? 0 : (float)nade.NAExpenseEntity.Transport,
                SchFees = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.SchFees == null ? 0 : (float)nade.NAExpenseEntity.SchFees,
                OtherExp = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.OthersExp == null ? 0 : (float)nade.NAExpenseEntity.OthersExp,
                LoanIns = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.LoanInstallments == null ? 0 : (float)nade.NAExpenseEntity.LoanInstallments,
                CredPay = nade.NAExpenseEntity == null ? 0 : nade.NAExpenseEntity.CreditPay == null ? 0 : (float)nade.NAExpenseEntity.CreditPay,

                //assets
                FixedDep = nade.NAAssetEntity == null ? 0 : nade.NAAssetEntity.FixedDepo == null ? 0 : (float)nade.NAAssetEntity.FixedDepo,
                Saving = nade.NAAssetEntity == null ? 0 : nade.NAAssetEntity.Savings == null ? 0 : (float)nade.NAAssetEntity.Savings,
                OthCey = nade.NAAssetEntity == null ? 0 : nade.NAAssetEntity.OthCeyInsu == null ? 0 : (float)nade.NAAssetEntity.OthCeyInsu,
                OthIns = nade.NAAssetEntity == null ? 0 : nade.NAAssetEntity.OthInsu == null ? 0 : (float)nade.NAAssetEntity.OthInsu,
                OthAss = nade.NAAssetEntity == null ? 0 : nade.NAAssetEntity.Others == null ? 0 : (float)nade.NAAssetEntity.Others,


                //spouse
                SpId = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.IDType == null ? nade.NASpouseEntity.IDNo : nade.NASpouseEntity.IDTypeEntity.Description + "-" + nade.NASpouseEntity.IDNo,
                SpName = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.Salutation == null ? nade.NASpouseEntity.Initial + " " + nade.NASpouseEntity.Surname : nade.NASpouseEntity.SalutationEntity.Description + " " + nade.NASpouseEntity.Initial + " " + nade.NASpouseEntity.Surname,
                SpOtherName = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.OtherName,
                SpDob = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.DOB.Value.ToShortDateString(),
                SpProfession = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.Profession,
                SpGender = nade.NASpouseEntity == null ? string.Empty : nade.NASpouseEntity.Gender,
                //prosp cols

                IdNo = nade.IDType == null ? string.Empty : nade.IDTypeEntity.Description + "-"+ nade.IDNumber,
                OtherName = nade.OtherName,
                Profession = nade.Profession,
                Address1 = nade.Address1,
                Address2 = nade.Address2,
                City = nade.City,
                Country = nade.Country == null ? string.Empty : nade.CountryEntity.Description ,
                HomePhone = nade.HomeTelephone,
                OfficePhone = nade.OfficeTelephone,
                Mobile = nade.Mobile,
                Email = nade.Email,
                PrefCall = nade.PrefNo,
                PrefPlace = nade.PrefPlace,
                ProsRem = nade.ProspRemarks



                 
            };

        }



        internal static NeedsAnalysisDetailEntity ToNeedsAnalysisEntity(NeedsAnalysis na)
        {
            return new NeedsAnalysisDetailEntity
            {
                NeedsAnalysisNo = na.NeedAnalysisNo,
                CustomerID = na.CustomerId,
                LastUpdated = Convert.ToDateTime(na.CreatedDate),
                SOCode = na.SoCode,

                ApprovalStatus = na.ApSt,
                Remarks = na.Remarks,
                //DOB = Convert.ToDateTime(na.Dob)

                 
            };
        }


        internal static CustomerEntity ToCustomersEntity(Customer c)
        {
            return new CustomerEntity
            {
                CustomerID = c.CustomerId,
                //IDType = c.IdType,
                FirstName = c.FirstName,
                            
            };
        }

        internal static ProspectEntity ToProspectsEntity(Prospect c)
        {
            return new ProspectEntity
            {
                ProspectID = c.ProspectId,
                //ProspectID = c.
                
            };
        }
        internal static NeedsAnalysisDetailEntity ToNeedAnalysisDetailEntity(NeedsAnalysis c)
        {
            return new NeedsAnalysisDetailEntity
            {
               // NeedsAnalysisNo = c.NeedAnalysisNo,

            };
        }

        #endregion


    }
}
